/*
 * 作者:熊猫
 * 日期:2017 - 3 - 15 0 - 0 - 14
 *
 */

package net.lainiao.morethread.Chapter6.demo4;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.DelayQueue;

/**
 * Created by Administrator on 2017/3/15.
 */
public class Task implements Runnable {
    private int id;
    private DelayQueue<Event> queue;

    public Task(int id, DelayQueue<Event> queue) {
        this.id = id;
        this.queue = queue;
    }

    @Override
    public void run() {
        Date now=new Date();
        Date delay=new Date();
        if(id<5){
            delay.setTime(now.getTime()+(id*1000));
        }else{
            delay.setTime(now.getTime()+(id*5000));
        }
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("该系列的事件将于"+format.format(delay)+" 执行");
        for (int i = 0; i < 100; i++) {
            Event event=new Event(delay);
            queue.add(event);
        }

    }
}
